﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.Master" AutoEventWireup="true" CodeBehind="frm_Listado.aspx.cs" Inherits="ED_Nivelacion.PresentacionWeb.frm_Paralelo" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <style type="text/css">
        .auto-style1 {
            width: 833px;
        }

        .auto-style2 {
            width: 390px;
        }

        .auto-style4 {
            width: 255px;
        }

        .auto-style5 {
            width: 187px;
        }
    </style>
    <form id="Form1" role="form" runat="server">
        <script>
           
            //$(document).ready(function () {
            // alert("");

            $(document).on("click", ".borrar", function () {
                   
                var id = $(this).data("paralelo");

                //alert(id);
                $('#ContentPlaceHolder1_idEliminar').val(id);

            });
            $(document).on("click", ".editar", function () {

                var id = $(this).data("idparalelo");
                var nombre = $(this).data("nombre");
                var periodo = $(this).data("periodo");
                var carrera = $(this).data("carrera");
                 

                $('#ContentPlaceHolder1_cbm_Carreras').val(carrera);
                $('#ContentPlaceHolder1_cbm_Periodo').val(periodo);
                $('#ContentPlaceHolder1_cbm_Paralelo').val(nombre);
                $('#ContentPlaceHolder1_idParalelo').val(id);

                $('#ContentPlaceHolder1_EditarBtn').show();
                $('#ContentPlaceHolder1_btm_Agregar').hide();
            });

            $(document).on("click", ".guardar", function () {
                var id = $(this).data("idcarrera");
                // 
                $('#ContentPlaceHolder1_cbm_Carreras').attr('disabled', 'disabled');
                $('#ContentPlaceHolder1_cbm_Carreras').val(id);
                $('#ContentPlaceHolder1_idcarrera').val(id);
                $('#ContentPlaceHolder1_btm_Agregar').show();
                $('#ContentPlaceHolder1_EditarBtn').hide();
            });

            $(document).on("click", ".asignar", function () {
                var idparalelo = $(this).data('idparalelo');
                alert(idparalelo);
                $('#ContentPlaceHolder1_txtParalelo').val(idparalelo);
                var periodo = <%=Session["PeriodoC"]%>
                    ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.ObtenerDistribucionAcademicaParalelo(idparalelo, onSuccess, onFailure);
            });

            function onSuccess(object)
            {
                var tabla2 = "";
                //alert(object.length);
                for (var i = 0; i < object.length; i++) {

                    var idist = object[i].idDistribucion_Academica;
                    var Asignatura = object[i].Nombre_Asignatura;
                    var Docent = object[i].Nombre + " " + object[i].Apellido;

                    var tabla = "<tr class='gradeA even'><td>" + idist + "</td><td>"+ Docent +"</td><td>" + Asignatura + "</td><td><a class='btn btn-danger btn-xs' onClick='eliminar(" + idist + ")'><span class='fa fa-trash-o'></span> Eliminar</a></td></tr>";
                    var tabla2 = tabla2.concat(tabla);
                }
                document.getElementById("Academico").innerHTML = tabla2;
                $('#Distribucion').dataTable();
            }

            function onFailure(object) {
                errorMessage("ERROR FATAL");
            }

            function agregar() {
                //Validar();
                var Docente = $('#ContentPlaceHolder1_CbmDocente').val();
                var Paralelo = $('#ContentPlaceHolder1_txtParalelo').val();
                var Asignatura = $('#ContentPlaceHolder1_CbmMateria').val();
                var Periodo = <%=Session["PeriodoC"]%>;


                var data = { idDocente: Docente, idPeriodo: Periodo, idAsignatura: Asignatura, idParalelo: Paralelo };
                ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.AgregarDistribucionAcademicaParalelo(data, mostrar, error);
                
            }

            function mostrar()
            {
                sucessMessage("Correcto!");
                var idParalelo = $('#ContentPlaceHolder1_txtParalelo').val();
                ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.ObtenerDistribucionAcademicaParalelo(idParalelo, onSuccess, onFailure);

            }
            function error()
            {
                errorMessage("ERROR FATAL");
            }

            function eliminar(id)
            {
                ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.EliminarDistribucionAcademicaParalelo(id,successEliminar,errorEliminar);
            }
            function successEliminar() {
                sucessMessage("Registro Eliminado Correctamente");
                mostrar();
            }
            function errorEliminar() {
                errorMessage("ERROR FATAL");
                
            }

            function Validar() {
                var Docente = $('#ContentPlaceHolder1_CbmDocente').val();
                var Paralelo = $('#ContentPlaceHolder1_txtParalelo').val();
                var Asignatura = $('#ContentPlaceHolder1_CbmMateria').val();
                var Periodo = <%=Session["PeriodoC"]%>;

                var param = {idParalelo: Paralelo, idAsignatura: Asignatura, idDocente: Docente, idPeriodo: Periodo};
                ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.ValidarDistribucionAcademica(param, mostrarV, errorV);
            }

            function mostrarV(data)
            {
                if (data == "OK") {
                    agregar();
                } else {
                    errorMessage("La pregunta ya fue ingresada en este cuestionario");
                } 
     
            }
            function errorV() { alert("ERROR"); }

            //});


        </script>

        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Services>
                <asp:ServiceReference Path="~/ServiciosLocales/CuestionarioService.asmx" />
            </Services>
        </asp:ScriptManager>
        <asp:Timer ID="Timer1" runat="server">
                                </asp:Timer>
        <asp:TextBox ID="idEliminar" runat="server" CssClass="hide"></asp:TextBox>
        <%-- <asp:LinkButton ID="BtnEliminar" runat="server" CssClass="btn btn-success btn-xs" OnClick="Delete_Click"><i class="fa fa-check-circle icon-white"></i> Si</asp:LinkButton>--%>

        <% ED_Nivelacion.Negocios.Carrera_C _objCa = new ED_Nivelacion.Negocios.Carrera_C();
           //ED_Nivelacion.Negocios.Carrera_C _objCa = new ED_Nivelacion.Negocios.Carrera_C();
           ED_Nivelacion.Negocios.Paralelo_C _obj = new ED_Nivelacion.Negocios.Paralelo_C();
           ED_Nivelacion.Negocios.Periodo_C _objPe = new ED_Nivelacion.Negocios.Periodo_C();
           var result_C = _objCa.ObtenerCarrera();
           foreach (var item in result_C)
           {
                                                       
        %>
        <div class="portlet-body">

            <div class="panel-group" id="accordion">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">

                            <a data-toggle="collapse" data-parent="#accordion" href="#collapse<%=item.idCarrera %>">
                                <%=item.CarreraNombre %>
                                                
                            </a>
                        </h4>

                    </div>
                    <div id="collapse<%=item.idCarrera %>" class="panel-collapse collapse">
                        <div class="panel-body">
                            <div class="col-lg-10">
                                <div class="portlet portlet-default">
                                    <div class="portlet-heading">
                                        <div class="portlet-title">
                                            <h4>Paralelos</h4>
                                        </div>
                                        <div class="portlet-widgets">
                                            <a class="btn btn-success btn-xs guardar" data-toggle="modal" data-target="#AgregarParalelo" data-idcarrera="<%=item.idCarrera %>"><i class="fa fa-plus">Agregar</i></a>
                                        </div>
                                        <div class="clearfix"></div>
                                    </div>

                                    <div class="portlet-body">

                                        <div class="table-responsive">
                                            <table class="table table-condensed">
                                                <thead>
                                                    <tr>
                                                        <th>#</th>
                                                        <th class="auto-style4">Carrera</th>
                                                        <th class="auto-style1">Periodo</th>
                                                        <th class="auto-style5">Descripcion</th>
                                                        <th class="auto-style2">Distribución</th>
                                                        <th class="auto-style2">Accion</th>
                                                    </tr>
                                                </thead>

                                                <tbody id="tablaParalelos">

                                                    <% 
               var result = _obj.FiltrarParalelo(item.idCarrera, int.Parse(Session["PeriodoC"].ToString()));


               foreach (var item_ in result)
               {
                                                    
                                               
                                                    %>
                                                    <tr>
                                                        <td><%=item_.idParalelo%></td>
                                                        <td class="auto-style4"><%=_objCa.FiltrarCarrera(item_.idCarrera).FirstOrDefault().CarreraNombre%></td>
                                                        <td class="auto-style1"><%=_objPe.FiltrarPeriodo(item_.idPeriodo).FirstOrDefault().Nombre_Periodo%></td>
                                                        <td class="auto-style5"><%=item_.ParaleloNombre%></td>
                                                        <td class="auto-style2"><a href="#" class="btn btn-green btn-large asignar" data-toggle="modal" data-target="#Asignar_Distribucion" data-idparalelo="<%=item_.idParalelo%>" data-carrera="<%=item_.idCarrera%>"><i class="icon-white fa fa-hand-o-right"></i>Asignar</a></td>
                                                        <td class="auto-style2"><a href="#" class="btn btn-orange btn-large editar" data-toggle="modal" data-target="#AgregarParalelo" data-nombre="<%=item_.ParaleloNombre%>" data-periodo="<%=item_.idPeriodo%>" data-idparalelo="<%=item_.idParalelo%>" data-carrera="<%=item_.idCarrera%>"><i class="icon-white icon-heart fa fa-pencil"></i>Modificar</a> <a class="btn btn-red btn-large borrar" data-toggle="confirmation" data-paralelo="<%=item_.idParalelo%>" data-placement="top" data-singleton="true"><i class="icon-white fa fa-trash-o"></i>Eliminar</a></td>
                                                    </tr>
                                                    <%} %>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <% } %>
        <!-- Condensed Responsive Table -->

        <!-- /.portlet -->
        <div class="col-lg-12">
            <div class="modal modal-flex fade in" id="AgregarParalelo" tabindex="-1" role="dialog" aria-labelledby="flexModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="flexModalLabel">Registrar Paralelos por Carrera</h4>
                        </div>


                        <div class="modal-body" runat="server">
                            <div class="form-group">
                                <asp:TextBox ID="idParalelo" CssClass="hide" runat="server"></asp:TextBox>
                                <asp:TextBox ID="idcarrera" CssClass="hide" runat="server"></asp:TextBox>
                                <label for="cbm_Carreras" class="">Carrera:</label><asp:DropDownList ID="cbm_Carreras" runat="server"></asp:DropDownList>

                            </div>

                            <div class="form-group">
                                <label for="cbm_Periodo" class="">Periodo:<asp:DropDownList ID="cbm_Periodo" runat="server"></asp:DropDownList></label>

                            </div>

                            <div class="form-group">
                                <label for="cbm_Paralelo" class="">
                                    Paralelo:<asp:DropDownList ID="cbm_Paralelo" runat="server">
                                        <asp:ListItem>A</asp:ListItem>
                                        <asp:ListItem>B</asp:ListItem>
                                    </asp:DropDownList></label>

                            </div>
                        </div>
                        <div class="modal-footer">

                            <asp:Button ID="btm_Agregar" runat="server" CssClass=" btn btn-primary" Text="AGREGAR" OnClick="btm_Agregar_Click" />
                            <asp:Button ID="EditarBtn" runat="server" CssClass=" btn btn-primary" Text="EDITAR" OnClick="EditarBtn_Click" />
                        </div>

                    </div>
                    <!-- /.modal-content -->
                </div>
                <!-- /.modal-dialog -->
            </div>
        </div>

        <div class="col-lg-22">
            <div class="modal modal-flex fade in" id="Asignar_Distribucion" tabindex="-1" role="dialog" aria-labelledby="flexModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="H1">Distribución Académica</h4>
                        </div>
                        <div id="Div3" class="modal-body">
                            <div class="table-responsive">
                                <table id="Distri" class="table table-striped table-bordered table-hover table-blue">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Nombre Docente:</th>
                                            <th>Materia:</th>
                                            <th>Acción:</th>
                                        </tr>
                                    </thead>
                                    <tbody id="Academico">
                                        <tr>
                                        </tr>
                                    </tbody>


                                </table>
                            </div>
                            <!-- /.table-responsive -->



                            <!-- /.portlet-body -->


                            <!-- /.portlet -->
                            <!-- <input type="text" id="txtParalelo"/> -->
                            <div class="modal-footer">
                                <asp:TextBox ID="txtParalelo" runat="server" CssClass="hide"></asp:TextBox>
                                <div class="form-group">
                                    <div class="col-lg-12">
                                        <div class="col-lg-3">
                                            <label>Docente:</label>
                                        </div>
                                        <div class="col-lg-9">
                                            <asp:DropDownList CssClass="form-control" style="width: 200px;" ID="CbmDocente" runat="server"></asp:DropDownList>
                                        </div>
                                    </div>
                                    <div class="col-lg-12">
                                        <div class="col-lg-3">
                                            <label>Materia:</label>
                                        </div>
                                        <div class="col-lg-9">
                                            <asp:DropDownList CssClass="form-control" style="width: 200px;" ID="CbmMateria" runat="server"></asp:DropDownList>
                                        </div>
                                    </div>
                                    <a id="btmPregunta" class=" btn btn-primary" onclick="Validar()">GUARDAR</a>
                                    <div class="clearfix"></div>
                                </div>
                            </div>


                        </div>


                    </div>
                    <!-- /.modal-content -->
                </div>
                <!-- /.modal-dialog -->
            </div>
        </div>




        <script>
            $('[data-paralelo]').click(function () {
                var Id = $(this).data('paralelo');
                $("#ContentPlaceHolder1_idEliminar").val(Id);
                //alert(Id);
            });
            $('[data-toggle="confirmation"]').confirmation({
                placement: 'top', // How to position the confirmation - top | bottom | left | right
                trigger: 'click', // How confirmation is triggered - click | hover | focus | manual
                title: 'Esta seguro?', // Default title value if `data-title` attribute isn't present  
                template: '<div class="popover" >' +
                    '<div class="arrow"></div>' +
                    '<h3 class="popover-title"></h3>' +
                    '<div class="popover-content text-center">' +
                    '<div id="botones" class="btn-group">' +
                    '<asp:LinkButton ID="BtnEliminar" runat="server" CssClass="btn btn-success btn-xs" OnClick="Delete_Click"><i class="fa fa-check-circle icon-white"></i> Si</asp:LinkButton>' +
                    '<a class="btn btn-xs" data-dismiss="confirmation"></a>' +
                    '</div>' +
                    '</div>'
                , btnOkClass: 'btn-primary'
                , btnOkIcon: 'fa fa-check-circle'
                , btnCancelClass: 'btn-danger'
                , btnOkLabel: 'Si'
                , btnCancelIcon: 'fa fa-times-circle'
                , btnCancelLabel: 'No',
                singleton: true, // Set true to allow only one confirmation to show at a time.
                popout: false, // Set true to hide the confirmation when user clicks outside of it.
                onConfirm: function () {

                }, // Set event when click at confirm button
                onCancel: function () { }
            }); // Set event when click at cancel button

            $(document).ready(function () {
                $("#<%Response.Write(CbmDocente.ClientID);%>").searchable(
                    {
                        maxListSize: 400,                       // if list size are less than maxListSize, show them all
                        maxMultiMatch: 10,                      // how many matching entries should be displayed
                        exactMatch: false,                      // Exact matching on search
                        wildcards: true,                        // Support for wildcard characters (*, ?)
                        ignoreCase: true,                       // Ignore case sensitivity
                        latency: 200,                           // how many millis to wait until starting search
                        warnMultiMatch: 'top {0} matches ...',  // string to append to a list of entries cut short by maxMultiMatch
                        warnNoMatch: 'No existen coincidencias',          // string to show in the list when no entries match
                        zIndex: 'auto'                          // zIndex for elements generated by this plugin
                    });
            
                $("#<%Response.Write(CbmMateria.ClientID);%>").searchable(
                        {
                            maxListSize: 400,                       // if list size are less than maxListSize, show them all
                            maxMultiMatch: 10,                      // how many matching entries should be displayed
                            exactMatch: false,                      // Exact matching on search
                            wildcards: true,                        // Support for wildcard characters (*, ?)
                            ignoreCase: true,                       // Ignore case sensitivity
                            latency: 200,                           // how many millis to wait until starting search
                            warnMultiMatch: 'top {0} matches ...',  // string to append to a list of entries cut short by maxMultiMatch
                            warnNoMatch: 'No existen coincidencias',          // string to show in the list when no entries match
                            zIndex: 'auto'                          // zIndex for elements generated by this plugin
                        });
            });
            ///version del browser
            jQuery.browser = {};
            (function () {
                jQuery.browser.msie = false;
                jQuery.browser.version = 0;
                if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
                    jQuery.browser.msie = true;
                    jQuery.browser.version = RegExp.$1;
                }
            })();
        </script>
    </form>
</asp:Content>
